package com.mall.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mall.demo.entity.User;
import com.mall.demo.mapper.UserMapper;
import com.mall.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/User")
public class UserController {

//    查询用户表
    @Autowired
    private UserMapper userMapper;

    @CrossOrigin
    @GetMapping("/getAllUser")
    public List text1(){
        List<User> users = userMapper.selectList(null);
        users.forEach(System.out::println);
        return users;
    }


    @CrossOrigin
    @GetMapping("/getOneUser")
    public List getOneUser(String name,String pass){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name" , name);
        wrapper.eq("password",pass);
        List<User> users =  userMapper.selectList(wrapper);
        return users;
    }

//    插入用户表
    @PostMapping("/insertOneUser")
    @CrossOrigin
    public int web_insert(@RequestBody User user)
    {
        int insert = userMapper.insert(user);
        System.out.println(insert);
        return insert;
    }


    @GetMapping
    @CrossOrigin
    public User getuserbyid(String id){
        User user = userMapper.selectById(id);
        return user;
    }
}
